<template>
  <div class='sub-category'>
    <div class="container" v-if="subData&&subData.parentId">
      <!-- 面包屑组件 -->
      <XtxBread seperator=">">
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem :to="`/category/${subData.parentId}`">{{subData.parentName}}</XtxBreadItem>
        <XtxBreadItem>{{subData.name}}</XtxBreadItem>
      </XtxBread>
       <!-- 筛选区 -->
      <div class="sub-filter">
        <!-- 规格  -->
        <div class="item" v-for="i in subData.saleProperties" :key="i.id">
          <div class="head">{{i.name}}：</div>
          <div class="body">
            <a href="javascript:;" v-for="item in i.properties" :key="item.id" :class="{ active: item.selected === true }" @click="toggleSelect(i.properties,item,i)">{{item.name}}</a>
          </div>
        </div>
      </div>
       <!-- 排序区域 -->
      <div class="list-container">
        <div class="sub-sort">
          <div class="sort">
            <a href="javascript:;" v-for="(item,index) in sortType" :key="index" @click="toggleSort(item.value)" :class="{active:curSortType===item.value}">{{item.name}}</a>
          </div>
        </div>
      </div>
      <!-- 商品列表 -->
      <div class="sort-list-container">
        <GoodsItem v-for="good in goodList" :key="good.id" :goods="good"></GoodsItem>
      </div>
      <!-- 上拉加载 -->
      <XtxInfiniteLoad @load="loadNext" :isFinited="isFinited" :isLoading="isLoading"></XtxInfiniteLoad>
    </div>
  </div>
</template>

<script>
import GoodsItem from '@/views/Home/components/home-goods.vue'
import { useLoadFilterData } from './service/useLoadFilterData'
import { useLoadListData } from './service/useLoadListData'
export default {
  name: 'SubCategory',
  components: {
    GoodsItem
  },
  setup () {
    // 加载筛选数据
    const { subData } = useLoadFilterData()
    // 列表筛选
    const { toggleSelect, sortType, toggleSort, curSortType, goodList, loadNext, isFinited, isLoading } = useLoadListData()

    return {
      subData,
      toggleSelect,
      sortType,
      toggleSort,
      curSortType,
      goodList,
      loadNext,
      isFinited,
      isLoading
    }
  }
}
</script>
<style scoped lang='less'>
.goods-list {
  background: #fff;
  padding: 0 25px;
  margin-top: 25px;
}
 // 筛选区
  .sub-filter {
    background: #fff;
    padding: 25px;
    .item {
      display: flex;
      padding: 10px 0;
      .head {
        width: 80px;
        color: #999;
      }
      .body {
        flex: 1;
        overflow-wrap: anywhere;
        a {
          margin-right: 36px;
          transition: all .3s;
          &.active,
          &:hover {
            color: @xtxColor;
          }
        }
      }
    }
  }
  .sub-sort {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .sort {
    display: flex;
    a {
      height: 30px;
      line-height: 28px;
      border: 1px solid #e4e4e4;
      padding: 0 20px;
      margin-right: 20px;
      color: #999;
      border-radius: 2px;
      position: relative;
      transition: all .3s;
      &.active {
        background: @xtxColor;
        border-color: @xtxColor;
        color: #fff;
      }
      .arrow {
        position: absolute;
        border: 5px solid transparent;
        right: 8px;
        &.up {
          top: 3px;
          border-bottom-color: #bbb;
            &.active {
            border-bottom-color: @xtxColor;
          }
        }
        &.down {
          top: 15px;
          border-top-color: #bbb;
          &.active {
            border-top-color: @xtxColor;
          }
        }
      }
    }
  }
  .check {
    .xtx-checkbox {
      margin-left: 20px;
      color: #999;
    }
  }
}
.list-container{
  margin-top: 20px;
  padding: 0 20px;
  background: #fff;
}
.sort-list-container {
  display: flex;
  flex-wrap: wrap;
  background: #fff;
}
</style>
